package cc.liyinghao.springsecuritydemo.config;

import cc.liyinghao.springsecuritydemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.userdetails.UserDetailsService;

/**
 * 单独包的security配置
 * 通常来说，security会单独放在一个包下
 * 这个是针对这个包下的security配置，个性化单独配置
 */
@Configuration
public class DemoSecurityConfig {

    @Autowired
    private UserService userService;

    /**
     * 获取登录用户信息
     */
    @Bean
    public UserDetailsService userDetailsService() {
        return username -> userService.loadUserByUsername(username);
    }
}
